/*
 *  Copyright 2008 Michael Brackx
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.googlecode.triples.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@Entity
@NamedQueries({
		@NamedQuery(name = "tripleById", query = "SELECT t FROM Triple t WHERE t.id = :id"),
		@NamedQuery(name = "tripleAll", query = "SELECT t FROM Triple t"),
		@NamedQuery(name = "tripleIds", query = "SELECT t.id FROM Triple t"),
		@NamedQuery(name = "tripleCount", query = "SELECT count(t) FROM Triple t"),
		@NamedQuery(name = "tripleByObjectAttribute", query = "SELECT t FROM Triple t WHERE t.object = :object AND t.attribute = :attribute"),
		@NamedQuery(name = "tripleIdsByObjectAttribute", query = "SELECT t.id FROM Triple t WHERE t.object = :object AND t.attribute = :attribute"),
		@NamedQuery(name = "tripleCountByObjectAttribute", query = "SELECT count(t) FROM Triple t WHERE t.object = :object AND t.attribute = :attribute"),
		@NamedQuery(name = "tripleValueByObjectAttribute", query = "SELECT t.value FROM Triple t WHERE t.object = :object AND t.attribute = :attribute")})
@Table(name = "triple")
@XmlRootElement
@XmlType(propOrder = {"object", "attribute", "value"})
public class Triple {

	private Long id;
	private String object;
	private String attribute;
	private String value;

	// getters & setters

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@XmlAttribute
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getObject() {
		return object;
	}

	public void setObject(String object) {
		this.object = object;
	}

	public String getAttribute() {
		return attribute;
	}

	public void setAttribute(String attribute) {
		this.attribute = attribute;
	}

	@Column(columnDefinition = "VARCHAR(10240)")
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	// object

	@Override
	public String toString() {
		return String.format("(%s %s %s)",getObject(), getAttribute(), getValue());
	}
}
